from math import inf
from typing import *


class Solution:
    def minChanges(self, nums: List[int], k: int) -> int:
        g = [DefaultDict(int) for _ in range(k)]
        cnt = [0] * k
        for i, v in enumerate(nums):
            g[i % k][v] += 1
            cnt[i % k] += 1
        a = [inf] * 1024
        a[0] = 0
        for ki in range(k):
            mn = min(a)
            b = [mn] * 1024
            for s in range(1024):
                for key, value in g[ki].items():
                    b[s] = min(b[s], a[s ^ key] - value)
            a = [v + cnt[ki] for v in b]
        return a[0]


s = Solution()
print(s.minChanges(nums=[3, 4, 5, 2, 1, 7, 3, 4, 7], k=3))
